package servlet;

import pojo.Book;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/DetailServlet")
@MultipartConfig
public class DetailServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ServletContext servletContext = this.getServletContext();
        String m=request.getParameter("m");
        if(m.equals("buyGoods")){
            toDetail(request,response);
        }


    }

    protected void toDetail(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Book book=new Book();
        book.setName(request.getParameter("name"));
        book.setImg(request.getParameter("img"));
        book.setAuthor(request.getParameter("author"));
        book.setDescript(request.getParameter("descript"));
        book.setPrice(Double.parseDouble(request.getParameter("price")));
        String username = request.getParameter("username");
        request.setAttribute("username",username);
        request.setAttribute("book",book);
        System.out.println(book);
        request.getRequestDispatcher("detail.jsp").forward(request,response);

    }

}
